package net.atomarrow.dispatcher;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.atomarrow.annotation.Inject;
import net.atomarrow.configs.Config;
import net.atomarrow.configs.DbConfig;
import net.atomarrow.configs.scan.ConfigScanner;
import net.atomarrow.inits.InitLoadProcessor;
import net.atomarrow.ioc.ApplicationContext;
import net.atomarrow.monitor.ClassAlterationMonitor;
import net.atomarrow.plugins.PluginManager;
/**
 * 入口filter
 * @author Michael
 *
 */
public class FilterDispatcher implements Filter{

    private ProcessDispatcher dispatcher = ApplicationContext.get(ProcessDispatcher.class);

    @Override
    public void destroy() {

    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse res,
            FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)req;
        request.setCharacterEncoding("UTF-8");
        HttpServletResponse response = (HttpServletResponse)res;
        boolean success = dispatcher.process(request, response);
        if(!success){
            chain.doFilter(request, response);
        }
    }

    @Override
    public void init(FilterConfig config) throws ServletException {

    }
}
